package com.tcm.login.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.user.model.query.LoginAuthQuery;
import com.tcm.user.service.SigninService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class SigninController {

    @DubboReference(version = "1.0.0", check = false, timeout = 3000)
    SigninService signinService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginAuthQuery loginAuthQuery) {
        try {
            return signinService.login(loginAuthQuery);
        }catch (ServiceException e){
            e.printStackTrace();
            return R.fail("小伙伴太热情了，请下次再来");
        }catch (Exception e){
            e.printStackTrace();
            return R.fail("小伙伴太热情了，请下次再来");
        }
    }

    /**
     * 获得短信验证码
     */
    @GetMapping("/sms/code")
    public R sendVerificationCode(@RequestParam String phone) {
        try {
            return signinService.sendVerificationCode(phone);
        }catch (ServiceException e){
            e.printStackTrace();
            return R.fail("小伙伴太热情了，请下次再来");
        }catch (Exception e){
            e.printStackTrace();
            return R.fail("小伙伴太热情了，请下次再来");
        }
    }


}
